< previous page page_717 next page >

Page 717
Sending a Template to the Browser
By default, a WebClass's Start event sends a few lines of HTML back to the browser. You can also send templates back to the browser, such as the sample just created, by using the WriteTemplate method. Open the Start event of the WebClass and replace the default lines of code with the following line:
Me.Template1.WriteTemplate
Run the application and the template based on the file TEST.HTM should be the first thing you see. Notice that the browser is not redirected to TEST.HTM, but instead the HTML from the template file is passed back during the Start event.
The WriteTemplate method can be very useful when combined with the ProcessTag event. This event can be used to dynamically generate HTML content, similar to the way you use Response.Write statements in an ASP page to generate HTML on-the-fly. It works by searching for tags within your template (much like HTML tags but with a special prefix) and replacing them with whatever information you choose.
To demonstrate this, again bring up the template file TEST.HTM. (Make sure to bring up the file in the project directory, not the original import file.) Add the following line to the template somewhere in the body of the document and save it:
<WC@mytag>My Information</WC@mytag>
The preceding line of code contains a "customized" tag, <WC@mytag>. During execution of the WriteHTMLTemplate method, each time the WebClass encounters a tag with the wc@ prefix, the ProcessTag event is fired. The tag name (mytag) and contents (My Information) are passed to the event and can be modified before being sent to the browser:
Private Sub Template1_ProcessTag(ByVal TagName As String, TagContents As String,
SendTags As Boolean)

If TagName = "WC@mytag" Then

    TagContents = "<B> Here is some new information </B>"

End If

End Sub
Using a Custom WebItem
The other type of WebItem that can be added to the WebClass is a custom WebItem. The events in a custom WebItem are just like the ones in an HTML Template WebItem, and you have the option to add your own custom events that can be raised from a Web page. However, there is no template in a Custom WebItem. It exists only in your VB code, as a set of event procedures. You can connect items in an HTML Template WebItem to a Custom WebItem with a few simple steps:
1. Right-click the WebClass's name in the Project Explorer window and choose View Object. The Designer window appears.

 
< previous page page_717 next page >